//
//  SXSystemNavigationSetting.m
//  SXDataManager-SXDataManager
//
//  Created by wangshuixin on 2019/1/10.
//

#import "SXSystemNavigationSetting.h"

@implementation SXSystemNavigationSetting

// 自定义导航栏的titleView小菊花旋转效果
+ (void)settingForDynamicTitleViewOnNavigationItem:(UINavigationItem *)navigationItem message:(NSString *)message {
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(30, 5, 70, 20)];
    UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    activityIndicator.frame = CGRectMake(0, 5, 20, 20);
    dispatch_async(dispatch_get_main_queue(), ^{
        navigationItem.titleView = titleView;
        title.text = message;
        title.textColor = [UIColor whiteColor];
        title.font = [UIFont fontWithName:@"PingFangSC-Medium" size:18];
        [titleView addSubview:title];
        [activityIndicator startAnimating];
        [titleView addSubview:activityIndicator];
    });
}

// 隐藏titleView小菊花旋转效果，并恢复导航栏Title
+ (void)dismissDynamicTitleViewOnNavigationItem:(UINavigationItem *)navigationItem {
    dispatch_async(dispatch_get_main_queue(), ^{
        navigationItem.titleView = nil;
    });
}

@end
